<?php
$this->breadcrumbs=array(
	'Deals'=>array('deal/admin'),
	$deal->referenceNo=>array('deal/view','id'=>$deal->id),
	'Attachments' => array('attachment/admin', 'dealId'=>$deal->id),
	'Assign Attachments'
);
?>

<h1>Assign Attachments to Deal #<?php echo $deal->referenceNo;?></h1>

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'Attachment-grid',
	'dataProvider'=>$dataProvider,
	'filter'=>$model,
	'selectableRows'=>2,
	'columns'=>CMap::mergeArray(array(
		array(
			'class'=>'CCheckBoxColumn',
			'value'=>'$data->id',
			'id'=>'toBeAssigned'
		),
		array(
			'name'=>'customerId',
			'value'=>'$data->customer->getFullName()',
		),
		'name',
		array(
			'name'=>'notes',
			'type'=>'raw',
			'value'=>'strlen($data->notes)>80?substr($data->notes,0,79)."...":$data->notes',
		),
		array(
			'name'=>'uploadDate',
			'value'=>'date("d/m/Y", strtotime($data->uploadDate))',
			'filter'=>'',
		),
		array(
			'name'=>'createUserId',
			'type'=>'raw',
			'value'=>'$data->createUserId?($data->createUser->firstName." ".$data->createUser->lastName):""',
			'filter'=>'',
		),
		array(
			'header'=>'Files',
			'value'=>'$data->attachmentFileCount'
		),
		array(
			'class'=>'CButtonColumn',
			'template'=>'{view}',
		),
	),GlobalConfiguration::isManageMode()?array(
/*		array(
			'name'=>'hidden',
			'type'=>'boolean',
			'filter'=>DataUtil::getOptionYesNo(),
		),*/
	):array()),
)); ?>

<!-- Assign Loan -->
<?php
echo CHtml::beginForm($this->createUrl('processAssign'),'post'); 
echo CHtml::hiddenField('assignedAttachments','',array('id'=>'assignedAttachments'));
echo CHtml::hiddenField('dealId',$deal->id);
echo CHtml::submitButton('Assign Selected',array('id'=>'assignActionSubmit','name'=>'assignAction')); 
Yii::app()->clientScript->registerScript('preventAssignFormSubmit','
$("#assignActionSubmit").click(function(eventArgs) {
	var values=[];
	$("[name=\"toBeAssigned[]\"]:checked").each(function(){
		values.push($(this).val());
	});
	if(values.length==0){
		alert("Please select loans to assign.");
		return false;
	}
	$("#assignedAttachments").val(values.join(","));
});
');
?>
<?php echo CHtml::endForm(); ?>
